package com.ydlclass;

import com.ydlclass.util.zookeeper.ZookeeperNode;
import com.ydlclass.util.zookeeper.ZookeeperUtil;
import lombok.extern.slf4j.Slf4j;
import org.apache.zookeeper.CreateMode;
import org.apache.zookeeper.ZooKeeper;

import java.util.List;
import java.util.concurrent.CountDownLatch;

/**
 * zookeeper集群注册中心的管理页面
 */
@Slf4j
public class Application {
    public static void main(String[] args) {
        //帮我们创建基础目录

        CountDownLatch countDownLatch = new CountDownLatch(1);
        //创建一个zookeeper实例
        ZooKeeper zooKeeper = ZookeeperUtil.createZookeeper();
        //定义节点和数据
        String basePath = "/yrpc-metadata";
        String providerPath = basePath + "/providers";
        String consumersPath = basePath + "/consumers";

        ZookeeperNode baseNode = new ZookeeperNode("/yrpc-metadata", null);
        ZookeeperNode providersNode = new ZookeeperNode(providerPath, null);
        ZookeeperNode consumersNode = new ZookeeperNode(consumersPath, null);

        List.of(baseNode, providersNode, consumersNode).forEach(node -> {
            ZookeeperUtil.createNode(zooKeeper, node, null, CreateMode.PERSISTENT);
        });

        ZookeeperUtil.close(zooKeeper);
    }
}
